//
//  NewJiFenViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/23.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewJiFenViewController.h"
#import "JTCSM.h"
#import "MyInfoView.h"
#import "HuankuanJiluTableViewCell.h"
#import "NewJiFenJiLvTableViewCell.h"

typedef enum {
    
    isJiFenJiLueType = 0,
    isJiFenZhuanQueType = 1,
    
}showViewType;

static CGFloat myinfoHeight = 50;
@interface NewJiFenViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate>
{
    UIView *backView;
}
@property (nonatomic,strong) UITableView *tableview;
@property (nonatomic,assign) showViewType showType;
@property (nonatomic,strong) UILabel *jifenLabel;
@property (nonatomic,strong) UILabel *leftLabel;
@property (nonatomic,strong) UILabel *rightLabel;
@end

@implementation NewJiFenViewController


- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.navigationController.delegate = self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.view.backgroundColor =RGBACOLOR(251, 251, 251, 1);
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    // Do any additional setup after loading the view.
    self.showType = isJiFenJiLueType;
    [self layoutsubViews];
}

- (void)layoutsubViews{
    
    UIImageView *headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERWith*0.466667)];
    headerImageView.image = [UIImage imageNamed:@"my积分背景.png"];
    [self.view addSubview:headerImageView];
    headerImageView.userInteractionEnabled = YES;
    
    
    UIImage * firstImage = [UIImage imageNamed:@"erweimafanhui.png"];
    CGRect firstFrame = CGRectMake(20, 20, 50, 44);
    CGFloat width = firstFrame.size.width;
    CGFloat height = firstFrame.size.height;
    CGFloat fanhuiimagesize = 20;
    UIButton * leftButton = [[UIButton alloc]initWithFrame:firstFrame];
    [leftButton setImage:firstImage forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(gotBack) forControlEvents:UIControlEventTouchUpInside];
    leftButton.imageEdgeInsets = UIEdgeInsetsMake((height-fanhuiimagesize)/2, 0, (height-fanhuiimagesize)/2, (width-fanhuiimagesize));
    [self.view addSubview:leftButton];
    //    140   150 110  0.35 0.375  0.275
    
    UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(0, 20, KCONTROLLERWith, 44) text:@"我的积分" font:20 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(255, 255, 255, 1) backgroundColor:nil];
    [self.view addSubview:titleLabel];
    
    self.jifenLabel = [UILabel initWithFrame:CGRectMake(0, 85, KCONTROLLERWith, myinfoHeight) text:@"350" font:36 textAlignment:NSTextAlignmentCenter texcolor:[UIColor whiteColor] backgroundColor:nil];
    [headerImageView addSubview:self.jifenLabel];
    
    CGRect rect = [df labelHeightWithContent:@"积分" width:1500 font:15];
    CGFloat imagesize = rect.size.height;
    CGFloat space = 10;
    CGFloat buttonSpace = (KCONTROLLERWith-imagesize-rect.size.width-space)/2;
    UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    titleButton.frame = CGRectMake(buttonSpace, KVIEW_Y(self.jifenLabel), rect.size.width+space+imagesize, imagesize);
    [titleButton setTitle:@"积分" forState:UIControlStateNormal];
    titleButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [titleButton setTitleColor:[df colorWithHexString:@"ffffff" alpha:1] forState:UIControlStateNormal];
    [titleButton setImage:[UIImage imageNamed:@"积分icon.png"] forState:UIControlStateNormal];
    titleButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, titleButton.LC_width-imagesize);
    titleButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imagesize, 0, 0);
    [headerImageView addSubview:titleButton];
    [self layoutSubview];
    
}

- (void)layoutSubview{
    CGFloat space = 20;
    CGFloat top = 28;
    backView = [[UIView alloc]initWithFrame:CGRectMake(space, KCONTROLLERWith*0.466667+top, KCONTROLLERWith-2*space, KCONTROLLERHeight-KCONTROLLERWith*0.466667-3*top)];
    backView.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    [self.view addSubview:backView];
    backView.userInteractionEnabled = YES;
    [df layerWithView:backView radius:10 width:0 color:nil];
    [df setTheViewYiYing:backView shadowColor:RGBACOLOR(222, 222, 222, 1) shadowOffset:CGSizeMake(3, 3) apla:1];
    
    self.leftLabel = [UILabel initWithFrame:CGRectMake(0, 0, backView.LC_width/2, myinfoHeight) text:@"积分纪录" font:15 textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"01c4cc" alpha:1] backgroundColor:[UIColor whiteColor]];
    [backView addSubview:self.leftLabel];
    self.leftLabel.userInteractionEnabled = YES;
    [df layerWithView:self.leftLabel radius:10 width:0 color:nil];

    
    self.rightLabel = [UILabel initWithFrame:CGRectMake(backView.LC_width/2, 0, backView.LC_width/2, myinfoHeight) text:@"赚积分" font:15 textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"999999" alpha:1] backgroundColor:nil];
    [backView addSubview:self.rightLabel];
    self.rightLabel.userInteractionEnabled = YES;
    [df layerWithView:self.rightLabel radius:10 width:0 color:nil];

    
    [df addTapGestureRecognizerWithTarget:self action:@selector(showView:) andaddView:self.leftLabel];
    [df addTapGestureRecognizerWithTarget:self action:@selector(showView:) andaddView:self.rightLabel];
    
    [self layoutTableView];
    
}
- (void)showView:(UITapGestureRecognizer *)tap{
    UILabel *label = (UILabel *)[tap view];
    if (self.leftLabel == label) {
        self.leftLabel.textColor = [df colorWithHexString:@"01c4cc" alpha:1];
        self.leftLabel.backgroundColor = [UIColor whiteColor];
        self.rightLabel.textColor = [df colorWithHexString:@"999999" alpha:1];
        self.rightLabel.backgroundColor = [UIColor clearColor];
        self.showType = isJiFenJiLueType;
       
    }
    if (self.rightLabel == label) {
        self.rightLabel.textColor = [df colorWithHexString:@"01c4cc" alpha:1];
        self.rightLabel.backgroundColor = [UIColor whiteColor];
        self.leftLabel.textColor = [df colorWithHexString:@"999999" alpha:1];
        self.leftLabel.backgroundColor = [UIColor clearColor];
        self.showType = isJiFenZhuanQueType;
    }
     [self.tableview reloadData];
}
- (void)layoutTableView{
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, myinfoHeight, backView.LC_width, backView.LC_height-myinfoHeight) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [backView addSubview:_tableview];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self setUpTableView];
    [df layerWithView:_tableview radius:10 width:0 color:nil];

    //    view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
}

- (void)setUpTableView{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [_tableview addHeaderWithTarget:self action:@selector(headerRereshing)];
    
    // 上拉加载
    [_tableview addFooterWithTarget:self action:@selector(footerRereshing)];
    
}
- (void)headerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self theRequestWithKeyWord:mykeyword];
    });
}
- (void)footerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self loadMoreDataRequestWithKeyWord:mykeyword];
        
    });
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
   
    if (self.showType == isJiFenJiLueType) {
         NSString *cellid = [NSString stringWithFormat:@"textfield%ld",(long)indexPath.row];
        NewJiFenJiLvTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
        if (cell == nil) {
            cell = [[NewJiFenJiLvTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
        }
         return cell;
    }else{
         NSString *cellid = [NSString stringWithFormat:@"zhuangtextfield%ld",(long)indexPath.row];
        HuankuanJiluTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
        if (cell == nil) {
            cell = [[HuankuanJiluTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid cellType:IsZhangDanType];
        }
        [cell setValueWithModel:indexPath];
        
         return cell;
    }
   
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 75;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
